package com.example.questionnaire.aop;

import com.example.questionnaire.exception.DuplicateException;
import com.example.questionnaire.exception.IllegalException;
import com.example.questionnaire.exception.NotFindException;
import com.example.questionnaire.mbg.comman.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionAdvice {

    @ExceptionHandler(NotFindException.class)
    public R handler1(NotFindException e) {
        return R.fail(e.getMessage() + " 不存在");
    }

    @ExceptionHandler(IllegalException.class)
    public R handler2(IllegalException e) {
        return R.fail(e.getMessage() + " 非法");
    }

    @ExceptionHandler(DuplicateException.class)
    public R handler3(DuplicateException e) {
        return R.fail(e.getMessage() + " 已存在");
    }
}
